package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleConfigService;
import com.heima.common.constants.WemediaConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

@Component
@Slf4j
public class ArticlelsDownListener {
    @Resource
    private ApArticleConfigService apArticleConfigService;


    @KafkaListener(topics = WemediaConstants.WM_NEWS_UP_DOWN_TOPIC)
    public void onMessage(String msg){
        log.info("ArticlelsDownListener:{}",msg);
        if (StringUtils.isNotBlank(msg)){
            Map map= JSON.parseObject(msg, Map.class);
            apArticleConfigService.updateByMap(map);
            log.info("article端文章配置修改，articleId={}",map.get("articleId"));
        }
    }
}
